package com.igeek.compus.study.notice.controller;

import com.igeek.compus.study.notice.entity.Notice;
import com.igeek.compus.study.notice.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @RequestMapping("list.do")
    @ResponseBody
    public Map list(Notice notice) {
        Map<String, Object> result = new HashMap<>();
        try {
            List<Notice> noticeList = noticeService.getNoticeList(notice);

            result.put("data", noticeList);
            result.put("count", noticeList.size());

            result.put("code", 0);
            result.put("msg", "查询成功");
        }catch (Exception e) {
            e.printStackTrace();
            result.put("code", 1);
            result.put("msg", "系统异常");
        }

        return result;
    }

    @RequestMapping("delete.do")
    @ResponseBody
    public Map delete(Notice notice) {
        System.out.println("11111");
        Map<String, Object> result = new HashMap<>();
        try {
            List<Notice> noticeList = noticeService.getNoticeList(notice);

            result.put("data", noticeList);
            result.put("count", noticeList.size());

            result.put("code", 0);
            result.put("msg", "查询成功");
        }catch (Exception e) {
            e.printStackTrace();
            result.put("code", 1);
            result.put("msg", "系统异常");
        }
        return result;
    }

}
